package org.itzixi.mapper;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.itzixi.api.feign.FileFein;
import org.itzixi.enums.Sex;
import org.itzixi.pojo.Users;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.itzixi.utils.LocalDateUtils;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.UUID;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author 顾文龙
 * @since 2024-06-12
 */
@Repository
public interface UsersMapper extends BaseMapper<Users> {


    default Users queryMobileIfExist(String mobile) {
        QueryWrapper<Users> usersQueryWrapper = new QueryWrapper<>();
        usersQueryWrapper.lambda().eq(Users::getMobile, mobile);
        return this.selectOne(usersQueryWrapper);
    }

    default Users addUser(String mobile, String nickname) {
        Users user = new Users();
        user.setCreatedTime(LocalDateTimeUtil.now());
        user.setUpdatedTime(LocalDateTimeUtil.now());
        user.setMobile(mobile);

        String uuid = UUID.randomUUID().toString();
        String[] uuidArr = uuid.split("-");
        String wxNum = "wx" + uuidArr[0] + uuidArr[1];
        user.setWechatNum(wxNum);
        user.setNickname(nickname);
        user.setSex(Sex.secret.type);
        user.setFace(StrUtil.EMPTY);
        user.setFriendCircleBg(StrUtil.EMPTY);
        user.setEmail(StrUtil.EMPTY);
        user.setBirthday(LocalDateTimeUtil.parseDate("1988-01-01", LocalDateUtils.DATE_PATTERN));
        user.setCountry("中国");
        user.setProvince(StrUtil.EMPTY);
        user.setCity(StrUtil.EMPTY);
        user.setDistrict(StrUtil.EMPTY);
        user.setWechatNumImg(StrUtil.EMPTY);
        String realName = "用户" + mobile;
        user.setRealName(realName);
//        this.insert(user);
        return user;
    }

}
